/**
 * @lastUpdateBy :
 * @description: 视廊数据管理相关api
 */
import qs from 'qs'; // 导入qs模块 增加了一些安全性的查询字符串解析和序列化字符串的库
let axiosWraper = agcim.net.axiosWraper;
export default {
    /**
     * @description: 获取视廊组数据
     * @param {Object} params 参数
     * @return {Promise}
     */
    getGalleryGroupStore(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getData(
                    agcim.net.apiPath.group_visual_tree,
                    params
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
    addGalleryGroup(params) {
        return new Promise((resolve, reject) => {
            axiosWraper.getDataByPost(agcim.net.apiPath.group_visual_add, qs.stringify(params))
                .then((response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                )
        })
    },
    renameGalleryGroup(params) {
        return new Promise((resolve, reject) => {
            axiosWraper.getDataByPost(agcim.net.apiPath.group_visual_reName, qs.stringify(params))
                .then((response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                )
        })
    },
    /**
     * @description 删除视廊组
     *
     * @param {*} id
     * @param {*} groupType
     * @param {*} userId
     * @return {*}
     */
    deleteGalleryGroup(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getData(agcim.net.apiPath.group_visual_delete,
                    {
                        id: params.id,
                        groupType: params.groupType,
                        userId: params.userId,
                    }
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
    /**
     *
     * @description 删除视廊
     * @param {*} params.id
     * @param {*} params.groupId
     * @return {*}
     */
    deleteGallery(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getData(agcim.net.apiPath.visual_delete,
                    {
                        ids: params.id,
                        groupId: params.groupId,
                        groupType: 0,
                    }
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
    /**
     * @description: 获取视廊列表数据
     * @param {Object} groupId 组id
     * @return {Promise}
     */
    getGalleryStore(groupId) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getData(
                    agcim.net.apiPath.group_gallerys, {groupId: groupId}
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },

    /**
     * @description: 新增数据
     * @param {Object} params
     * @return {Promise}
     */
    saveImageStore(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getDataByPost(
                    agcim.net.apiPath.io_imagestore_save,
                    qs.stringify(params)
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },


    /**
     * @description: 更新数据
     * @param {Object} params
     * @return {Promise}
     */
    updateImageStore(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .getDataByPost(
                    agcim.net.apiPath.io_imagestore_update,
                    qs.stringify(params)
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },


    /**
     *
     * @param {Object} params
     * @returns {Promise}
     */
    deleteImageStore(params) {
        return new Promise((resolve, reject) => {
            axiosWraper
                .delete(agcim.net.apiPath.io_imagestore_deleteById, params)
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    }
};
